﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelperPrototype.OtherForms
{
    public partial class XemPhieuDanhGiaNCC : Form
    {
        private string _maPhieu;

        public XemPhieuDanhGiaNCC(string maPhieuDanhGiaNCC)
        {
            InitializeComponent();
            _maPhieu = maPhieuDanhGiaNCC;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void XemPhieuDanhGiaNCC_Load(object sender, EventArgs e)
        {
            loadData();
        }

        private void loadData()
        {
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            _DB.PhieuDanhGiaNCC p = dc.PhieuDanhGiaNCCs.Single(x => x.MaPhieu == _maPhieu);

            txtMaPhieu.Text = p.MaPhieu;
            txtNguoiTao.Text = p.NguoiTao.Ten;
            txtPhongBan.Text = (p.NguoiTao.PhongBan == null) ? "" : p.NguoiTao.PhongBan.TenPhongBan;
            txtNoiDung.Text = p.Content;
            txtTrangThai.Text = p.TrangThaiPhieu.MoTa;

            // fill grid
            int count = 1;
            dgvHangHoa.Rows.Clear();
            foreach (_DB.HangHoa_NhaCungCap h in p.HangHoa_NhaCungCaps)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dgvHangHoa);
                r.Cells[0].Value = count++;
                r.Cells[1].Value = h.HangHoa.TenHangHoa;
                r.Cells[2].Value = h.NhaCungCap.TenNhaCungCap;
                r.Cells[3].Value = h.ChatLuong;
                r.Cells[4].Value = h.Gia;
                r.Cells[5].Value = h.ThoiGianGiaoHang;
                r.Cells[6].Value = h.HauMai;
                r.Cells[7].Value = h.HinhThucThanhToan;
                r.Cells[8].Value = h.Dat;
                r.Cells[9].Value = h.GhiChu;

                dgvHangHoa.Rows.Add(r);
            }
        }
    }
}
